trigger LeadDuplicatePreventer on Lead (before insert,before update) {
Map<string,lead> leadmap=new Map<string,lead>();
for(Lead lead:System.trigger.new){
    if((lead.email!=null)&&(System.Trigger.isinsert ||(lead.email!= System.Trigger.Oldmap.get(lead.id).email))){
     if(leadmap.containskey(lead.email)) {
         lead.email.adderror('another new lead'+'has the same email');
     }  else{
         leadmap.put(lead.email,lead);
     }
    }
    }
    for(Lead lead:[Select email from lead where email in :leadmap.keyset()]){
        Lead newlead=leadmap.get(lead.email);
        newlead.email.adderror('a lead with this email address exist');
    }
    


}